<template>
  <div>
    <v-chart :forceFit="true" :height="height" :data="data" :scale="scale">
      <v-coord type="rect" direction="LB" />
      <v-tooltip />
      <v-axis data-key="value" :label="label" />
      <v-bar position="label*value" />
    </v-chart>
  </div>
</template>

<script lang="ts">
const DataSet = require("@antv/data-set");
import { Base } from "../../../models/Chat/BaseBar";
import { Component, Vue, Prop, Emit } from "vue-property-decorator";

@Component({
  name: "chart-basebar",

  layout: "menu"
})
export default class ChartBaseBar extends Vue {
  @Prop({ type: Number, default: 400 }) height?: number;
  @Prop({ type: String, default: "" }) alias?: string;
  @Prop({ type: Array, default: 400 }) sourceData?: Base[];
  data: object = {};
  label: object = {
    offset: 20,
    formatter(val: string) {
      return val;
    }
  };
  scale: any[] = [
    {
      dataKey: "value",
      alias: this.alias
    }
  ];
  created() {
    const dv = new DataSet.View().source(this.sourceData);
    dv.transform({
      type: "sort",
      callback(a, b) {
        return a.population - b.population > 0;
      }
    });
    this.data = dv.rows;
  }
}
</script>

<style lang='less' scoped>
</style>